import http from '@/utils/http'
import { createSlice, createAsyncThunk } from '@reduxjs/toolkit'
import type { PayloadAction } from '@reduxjs/toolkit'

type Detail = {
  [key: string]: {
    [key: string]: string
  }
}
export type Infos = {
  userid: string
  detail: Detail
  time: Detail
  [key: string]: unknown
}

export type SignsState = {
  infos: Infos
}
type Time = {
  userid: string
}

export const getTimeAction = createAsyncThunk(
  'signs/getTimeAction',
  async (payload: Time) => {
    const res = await http.get('/signs/time', payload)
    return res.data
  }
)

export const putTimeAction = createAsyncThunk(
  'signs/putTimeAction',
  async (payload: Time) => {
    const res = await http.put('/signs/time', payload)
    return res.data
  }
)

const signsSlice = createSlice({
  name: 'signs',
  initialState: {
    infos: {},
  } as SignsState,
  reducers: {
    setInfos(state, action: PayloadAction<Infos>) {
      state.infos = action.payload
    },
  },
})

export const { setInfos } = signsSlice.actions

export default signsSlice.reducer
